package com.hdy.springcloud.controller;

import com.hdy.springcloud.mapper.Dept;
import com.hdy.springcloud.service.DeptClientService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import java.util.List;

@RestController
public class DeptConsumerController {
    //理解：消费者，不应该有service层
    //service层该怎么拿呢？    通过URL去请求
    //我们需要通过Restful去请求service层
    //RestTemplate 模板里面有很多方法，我们直接调用就可以了！注册到Spring中
    //(url,实体：Map,Class<T> responseType)



    @Autowired
    DeptClientService deptClientService = null;

    @RequestMapping("/consumer/dept/get/{id}")
    public Dept get(@PathVariable("id") long id){

        return this.deptClientService.queryDeptById(id);

    }

    @RequestMapping("/consumer/dept/add")
    // 这里消费者传递了参数后，生产者端需要在controller层使用@RequestBody注解来接收这个参数，
    // 如果生产者端不使用@RequestBody注解，那么生产者将接收不到消费者所传递的参数。
    public boolean add(Dept dept){
        System.out.println(dept);
        return this.deptClientService.addDept(dept);
    }

    @GetMapping("/consumer/dept/list")
    public List<Dept> list(){
        return this.deptClientService.queryDeptAll();
    }














}
